import {getTalks,deleteTalk,getAllTalkComment} from '@/api/talk'
const state = {
  talks:[],
  total:0,
  commentList:[]
}
const mutations = {
  SET_TALKS(state, data) {
    state.talks = data;
  },
  SET_TOTAL(state, data) {
    state.total = data;
  },
  SET_COMMENTLIST(state, data) {
    state.commentList = data;
  }
}

const actions = {
  async getTalks({commit},data){
    let result = await getTalks(data);
    if(result.code === 200){
      commit('SET_TALKS',result.talks);
      commit('SET_TOTAL',result.total);
    }
  },
  async delTalk({commit},id){
    let result = await deleteTalk(id);
    return result.code
  },
  async getAllTalkComment({commit}, data) {
    let result = await getAllTalkComment(data);
    commit('SET_COMMENTLIST',result.comments);
    commit('SET_TOTAL',result.total);
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

